﻿using System;
using System.Collections.Generic;
using System.Data;

namespace Isaac.Joy.Ormapping.Contract
{
    public interface IDatabase
    {
        /// <summary>
        /// 执行sql，返回受影响行数
        /// </summary>
        /// <param name="sql">sql正文</param>
        /// <param name="param">参数</param>
        /// <param name="transaction">事物对象</param>
        /// <param name="commandTimeout">连接时间</param>
        /// <param name="commandType">命令类型</param>
        /// <returns></returns>
        int Execute(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null);
        /// <summary>
        /// 执行sql，返回数据连接
        /// </summary>
        /// <param name="sql">sql正文</param>
        /// <param name="param">参数</param>
        /// <param name="transaction">事物对象</param>
        /// <param name="commandTimeout">连接时间</param>
        /// <param name="commandType">命令类型</param>
        /// <returns></returns>
        IDataReader ExecuteReader(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null);
        /// <summary>
        /// 执行sql，返回第一行第一列对象
        /// </summary>
        /// <param name="sql">sql正文</param>
        /// <param name="param">参数</param>
        /// <param name="transaction">事物对象</param>
        /// <param name="commandTimeout">连接时间</param>
        /// <param name="commandType">命令类型</param>
        /// <returns></returns>
        object ExecuteScalar(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null);
        /// <summary>
        /// 执行sql，返回第一行第一列对象
        /// </summary>
        /// <typeparam name="T">第一行第一列对象类型</typeparam>
        /// <param name="sql">sql正文</param>
        /// <param name="param">参数</param>
        /// <param name="transaction">事物对象</param>
        /// <param name="commandTimeout">连接时间</param>
        /// <param name="commandType">命令类型</param>
        /// <returns></returns>
        T ExecuteScalar<T>(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null);

        /// <summary>
        /// 执行sql，返回对象集合
        /// </summary>
        /// <typeparam name="T">数据映射的类型</typeparam>
        /// <param name="sql">sql正文</param>
        /// <param name="param">参数</param>
        /// <param name="transaction">事物对象</param>
        /// <param name="buffered">是否缓冲结果集</param>
        /// <param name="commandTimeout">连接时间</param>
        /// <param name="commandType">命令类型</param>
        /// <returns></returns>
        IEnumerable<T> Query<T>(string sql, object param = null, IDbTransaction transaction = null, bool buffered = true, int? commandTimeout = null, CommandType? commandType = null);
        /// <summary>
        /// 执行sql，返回对象集合
        /// </summary>
        /// <typeparam name="TReturn"></typeparam>
        /// <param name="sql"></param>
        /// <param name="types"></param>
        /// <param name="map"></param>
        /// <param name="param"></param>
        /// <param name="transaction"></param>
        /// <param name="buffered"></param>
        /// <param name="splitOn"></param>
        /// <param name="commandTimeout"></param>
        /// <param name="commandType"></param>
        /// <returns></returns>
        IEnumerable<TReturn> Query<TReturn>(string sql, Type[] types, Func<object[], TReturn> map, dynamic param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null);
        /// <summary>
        /// 执行sql，返回动态类型对象集合
        /// </summary>
        /// <param name="sql">sql正文</param>
        /// <param name="param">参数</param>
        /// <param name="transaction">事物对象</param>
        /// <param name="buffered">是否缓冲结果集</param>
        /// <param name="commandTimeout">连接时间</param>
        /// <param name="commandType">命令类型</param>
        /// <returns></returns>
        IEnumerable<dynamic> Query(string sql, object param = null, IDbTransaction transaction = null, bool buffered = true, int? commandTimeout = null, CommandType? commandType = null);
        /// <summary>
        /// 执行sql，返回对象集合
        /// </summary>
        /// <param name="type">对象类型</param>
        /// <param name="sql">sql正文</param>
        /// <param name="param">参数</param>
        /// <param name="transaction">事物对象</param>
        /// <param name="buffered">是否缓冲结果集</param>
        /// <param name="commandTimeout">连接时间</param>
        /// <param name="commandType">命令类型</param>
        /// <returns></returns>
        IEnumerable<object> Query(Type type, string sql, object param = null, IDbTransaction transaction = null, bool buffered = true, int? commandTimeout = null, CommandType? commandType = null);

        /// <summary>
        /// 执行sql，返回对象集合
        /// </summary>
        /// <typeparam name="TFirst">第一个对象</typeparam>
        /// <typeparam name="TSecond">第二个对象</typeparam>
        /// <typeparam name="TReturn">返回对象</typeparam>
        /// <param name="sql">sql正文</param>
        /// <param name="map">定义映射关系的表达式</param>
        /// <param name="param">参数</param>
        /// <param name="transaction">事物对象</param>
        /// <param name="buffered">是否缓冲结果集</param>
        /// <param name="splitOn"></param>
        /// <param name="commandTimeout">连接时间</param>
        /// <param name="commandType">命令类型</param>
        /// <returns></returns>
        IEnumerable<TReturn> Query<TFirst, TSecond, TReturn>(string sql, Func<TFirst, TSecond, TReturn> map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null);
        /// <summary>
        /// 执行sql，返回对象集合
        /// </summary>
        /// <typeparam name="TFirst">第一个对象</typeparam>
        /// <typeparam name="TSecond">第二个对象</typeparam>
        /// <typeparam name="TThird">第三个对象</typeparam>
        /// <typeparam name="TReturn">返回对象</typeparam>
        /// <param name="sql">sql正文</param>
        /// <param name="map">定义映射关系的表达式</param>
        /// <param name="param">参数</param>
        /// <param name="transaction">事物对象</param>
        /// <param name="buffered">是否缓冲结果集</param>
        /// <param name="splitOn"></param>
        /// <param name="commandTimeout">连接时间</param>
        /// <param name="commandType">命令类型</param>
        /// <returns></returns>
        IEnumerable<TReturn> Query<TFirst, TSecond, TThird, TReturn>(string sql, Func<TFirst, TSecond, TThird, TReturn> map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null);
        /// <summary>
        /// 执行sql，返回对象集合
        /// </summary>
        /// <typeparam name="TFirst">第一个对象</typeparam>
        /// <typeparam name="TSecond">第二个对象</typeparam>
        /// <typeparam name="TThird">第三个对象</typeparam>
        /// <typeparam name="TFourth">第四个对象</typeparam>
        /// <typeparam name="TReturn">返回对象</typeparam>
        /// <param name="sql">sql正文</param>
        /// <param name="map">定义映射关系的表达式</param>
        /// <param name="param">参数</param>
        /// <param name="transaction">事物对象</param>
        /// <param name="buffered">是否缓冲结果集</param>
        /// <param name="splitOn"></param>
        /// <param name="commandTimeout">连接时间</param>
        /// <param name="commandType">命令类型</param>
        /// <returns></returns>
        IEnumerable<TReturn> Query<TFirst, TSecond, TThird, TFourth, TReturn>(string sql, Func<TFirst, TSecond, TThird, TFourth, TReturn> map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null);
        /// <summary>
        /// 执行sql，返回对象集合
        /// </summary>
        /// <typeparam name="TFirst">第一个对象</typeparam>
        /// <typeparam name="TSecond">第二个对象</typeparam>
        /// <typeparam name="TThird">第三个对象</typeparam>
        /// <typeparam name="TFourth">第四个对象</typeparam>
        /// <typeparam name="TFifth">第五个对象</typeparam>
        /// <typeparam name="TReturn">返回对象</typeparam>
        /// <param name="sql">sql正文</param>
        /// <param name="map">定义映射关系的表达式</param>
        /// <param name="param">参数</param>
        /// <param name="transaction">事物对象</param>
        /// <param name="buffered">是否缓冲结果集</param>
        /// <param name="splitOn"></param>
        /// <param name="commandTimeout">连接时间</param>
        /// <param name="commandType">命令类型</param>
        /// <returns></returns>
        IEnumerable<TReturn> Query<TFirst, TSecond, TThird, TFourth, TFifth, TReturn>(string sql, Func<TFirst, TSecond, TThird, TFourth, TFifth, TReturn> map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null);
        /// <summary>
        /// 执行sql，返回对象集合
        /// </summary>
        /// <typeparam name="TFirst">第一个对象</typeparam>
        /// <typeparam name="TSecond">第二个对象</typeparam>
        /// <typeparam name="TThird">第三个对象</typeparam>
        /// <typeparam name="TFourth">第四个对象</typeparam>
        /// <typeparam name="TFifth">第五个对象</typeparam>
        /// <typeparam name="TSixth">第六个对象</typeparam>
        /// <typeparam name="TReturn">返回对象</typeparam>
        /// <param name="sql">sql正文</param>
        /// <param name="map">定义映射关系的表达式</param>
        /// <param name="param">参数</param>
        /// <param name="transaction">事物对象</param>
        /// <param name="buffered">是否缓冲结果集</param>
        /// <param name="splitOn"></param>
        /// <param name="commandTimeout">连接时间</param>
        /// <param name="commandType">命令类型</param>
        /// <returns></returns>
        IEnumerable<TReturn> Query<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TReturn>(string sql, Func<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TReturn> map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null);
        /// <summary>
        /// 执行sql，返回对象集合
        /// </summary>
        /// <typeparam name="TFirst">第一个对象</typeparam>
        /// <typeparam name="TSecond">第二个对象</typeparam>
        /// <typeparam name="TThird">第三个对象</typeparam>
        /// <typeparam name="TFourth">第四个对象</typeparam>
        /// <typeparam name="TFifth">第五个对象</typeparam>
        /// <typeparam name="TSixth">第六个对象</typeparam>
        /// <typeparam name="TSeventh">第七个对象</typeparam>
        /// <typeparam name="TReturn">返回对象</typeparam>
        /// <param name="sql">sql正文</param>
        /// <param name="map">定义映射关系的表达式</param>
        /// <param name="param">参数</param>
        /// <param name="transaction">事物对象</param>
        /// <param name="buffered">是否缓冲结果集</param>
        /// <param name="splitOn"></param>
        /// <param name="commandTimeout">连接时间</param>
        /// <param name="commandType">命令类型</param>
        /// <returns></returns>
        IEnumerable<TReturn> Query<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TReturn>(string sql, Func<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TReturn> map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null);
    }
}